package com.bilibili.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bilibili.entity.User;
import com.bilibili.service.AdminisService;
import com.bilibili.service.impl.AdminisServiceImpl;
@WebServlet("/admins.do")
public class AdminsServlet extends HttpServlet{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setContentType("text/html;charset=UTF-8");
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		AdminisService as = new AdminisServiceImpl();
		User user = as.selectUser(username, password);
        if (user != null) {
            req.getSession().setAttribute("adminUser", user);
            req.getRequestDispatcher("backVideo.html").forward(req, resp);
        } else {
            req.setAttribute("errorMsg", "用户名或密码错误");
            req.getRequestDispatcher("backLogin.html").forward(req, resp);
        }
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
}
